package com.study.javaFx.model;

import javafx.beans.property.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;

@JsonIgnoreProperties(ignoreUnknown = true)
public class Usage {

    private final IntegerProperty usageId;
    private final IntegerProperty machineId;
    private final IntegerProperty userId;
    private final IntegerProperty staffId;
    private final StringProperty startTime;
    private final StringProperty endTime;
    private final IntegerProperty duration;
    private final ObjectProperty<BigDecimal> cost;
    private final StringProperty paymentStatus;

    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @JsonCreator
    public Usage(
            @JsonProperty("usageId") int usageId,
            @JsonProperty("machineId") int machineId,
            @JsonProperty("userId") int userId,
            @JsonProperty("staffId") int staffId,
            @JsonProperty("startTime") String startTime,
            @JsonProperty("endTime") String endTime,
            @JsonProperty("duration") Integer duration,
            @JsonProperty("cost") BigDecimal cost,
            @JsonProperty("paymentStatus") String paymentStatus
    ) {
        this.usageId = new SimpleIntegerProperty(usageId);
        this.machineId = new SimpleIntegerProperty(machineId);
        this.userId = new SimpleIntegerProperty(userId);
        this.staffId = new SimpleIntegerProperty(staffId);
        this.startTime = new SimpleStringProperty(startTime != null ? startTime : "");
        this.endTime = new SimpleStringProperty(endTime != null ? endTime : "");
        this.duration = new SimpleIntegerProperty(duration != null ? duration : 0);
        this.cost = new SimpleObjectProperty<>(cost != null ? cost : BigDecimal.ZERO);
        this.paymentStatus = new SimpleStringProperty(paymentStatus != null ? paymentStatus : "");
    }

    public Usage() {
        this.usageId = new SimpleIntegerProperty(0);
        this.machineId = new SimpleIntegerProperty(0);
        this.userId = new SimpleIntegerProperty(0);
        this.startTime = new SimpleStringProperty("");
        this.endTime = new SimpleStringProperty("");
        this.staffId = new SimpleIntegerProperty(0);
        this.duration = new SimpleIntegerProperty(0);
        this.cost = new SimpleObjectProperty<>(BigDecimal.ZERO);
        this.paymentStatus = new SimpleStringProperty("");
    }

    // --- Getters and Property Getters ---

    @JsonProperty("usageId")
    public int getUsageId() { return usageId.get(); }
    @JsonProperty("usageId")
    public void setUsageId(int id) { this.usageId.set(id); }
    public IntegerProperty usageIdProperty() { return usageId; }

    @JsonProperty("machineId")
    public int getMachineId() { return machineId.get(); }
    @JsonProperty("machineId")
    public void setMachineId(int id) { this.machineId.set(id); }
    public IntegerProperty machineIdProperty() { return machineId; }

    @JsonProperty("userId")
    public int getUserId() { return userId.get(); }
    @JsonProperty("userId")
    public void setUserId(int id) { this.userId.set(id); }
    public IntegerProperty userIdProperty() { return userId; }

    public int getStaffId() { return staffId.get(); }
    public void setStaffId(int id) { this.staffId.set(id); }
    public IntegerProperty staffIdProperty() { return staffId; }

    @JsonProperty("startTime")
    public String getStartTime() { return startTime.get(); }
    @JsonProperty("startTime")
    public void setStartTime(String s) { this.startTime.set(s); }
    public StringProperty startTimeProperty() { return startTime; }

    @JsonProperty("endTime")
    public String getEndTime() { return endTime.get(); }
    @JsonProperty("endTime")
    public void setEndTime(String s) { this.endTime.set(s); }
    public StringProperty endTimeProperty() { return endTime; }

    public int getDuration() { return duration.get(); }
    public IntegerProperty durationProperty() { return duration; }

    public BigDecimal getCost() { return cost.get(); }
    public ObjectProperty<BigDecimal> costProperty() { return cost; }

    public String getPaymentStatus() { return paymentStatus.get(); }
    public StringProperty paymentStatusProperty() { return paymentStatus; }
} 